﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Hosting;
using EPiServer.Web.Hosting;
using System.Collections.Specialized;
using EPiServer.Security;

namespace EPiServer.CdnSupport.Test
{
    /// <summary>
    /// Wrapper class for unit testing
    /// </summary>
    class TestVirtualPathProvider : VirtualPathUnifiedProvider
    {
        public TestVirtualPathProvider(string name, NameValueCollection config) : base(name,config)
        {}
        public override VirtualFile GetFile(string virtualPath)
        {
            if (virtualPath == "/PageFiles/logo.png")
                return new VirtualFileEx2("/PageFiles/logo.png");
            else if (virtualPath == "/Secured/logo.png")
                return new UnifiedFile2("/Secured/logo.png",true);
            else if (virtualPath == "/Open/logo.png")
                return new UnifiedFile2("/Open/logo.png",false);
            else
                return null;
        }
    }

    public class VirtualPathUnifiedProvider2 : VirtualPathUnifiedProvider
    {
        public VirtualPathUnifiedProvider2() : base("test",new NameValueCollection())
        {

        }
    }

    public class UnifiedDirectory2 : UnifiedDirectory
    {
        AccessControlList _a;

        public UnifiedDirectory2(bool secured)
            : base(new VirtualPathUnifiedProvider2(), "/Secured", null, false)
        {
            _a = new AccessControlList();
            if(secured)
                _a.Add(new AccessControlEntry("SuperUser", AccessLevel.Read));
            else
                _a.Add(new AccessControlEntry("Everyone", AccessLevel.Read));
        }

        public override AccessControlList ACL
        {
            get
            {
                return _a;  
            }
        }

    }
    public class UnifiedFile2 : UnifiedFile
    {
        bool _secured;

        public UnifiedFile2(string virtualPath, bool secured)
            : base(new UnifiedDirectory2(secured), new VirtualPathUnifiedProvider2(), virtualPath, false)
        {
            _secured = secured;
        }

        public override DateTime Changed
        {
            get
            {
                return new DateTime(2000, 1, 2, 3, 4, 5);
            }
        }

        public override UnifiedDirectory Parent
        {
            get
            {
                return new UnifiedDirectory2(_secured);
            }
        }

        public override System.IO.Stream Open()
        {
            throw new NotImplementedException();
        }

        public override string PermanentLinkVirtualPath
        {
            get { return "/nisse"; }
        }
    }

    public class VirtualFileEx2 : VirtualFileEx
    {
        public VirtualFileEx2(string virtualPath)
            : base(virtualPath)
        { }

        public override DateTime Changed
        {
            get
            {
                return new DateTime(2000, 1, 2, 3, 4, 5);
            }
        }

        public override System.IO.Stream Open()
        {
            throw new NotImplementedException();
        }
    }
}
